/**
 * @deprecated 文本的基础类
 */

import { LengthRegexp, ColorRegexp, FontWeightRegexp } from '../../utils/const.js'
import BaseElement from './base.js'

export default class TextBaseElement extends BaseElement {
    /**
     * 字体大小
     */
    get size() {
        return this.getCss('font-size')
    }

    /**
     * 字体大小
     */
    set size(val) {
        if (/^\d+$/.test(`${val}`)) {
            val = `${val}px`
        }
        this.setCss('font-size', val)
    }

    /**
     * 字宽/字粗
     */
    get bold() {
        return this.getCss('font-weight')
    }

    /**
     * 字宽/字粗
     */
    set bold(val) {
        if (!FontWeightRegexp.test(`${val}`)) {
            val = val === true ? 'bold' : null
        }
        this.setCss('font-weight', val)
    }

    /**
     * 斜体
     */
    get italic() {
        return this.getCss('font-style')
    }

    /**
     * 斜体
     */
    set italic(val) {
        if (!/^(italic|oblique)$/.test(`${val}`)) {
            val = val === true ? 'italic' : null
        }
        this.setCss('font-style', val)
    }

    /**
     * 字体
     */
    get family() {
        return this.getCss('font-family')
    }

    /**
     * 字体
     */
    set family(val) {
        if (typeof val !== 'string') {
            val = null
        }
        this.setCss('font-family', val)
    }

    /**
     * 文本修饰线
     */
    get decoration() {
        return this.getCss('text-decoration')
    }

    /**
     * 文本修饰线
     */
    set decoration(val) {
        this.setCss('text-decoration', val)
    }

    /**
     * 文本修饰线：线条的类型
     */
    get decorationLine() {
        return this.getCss('text-decoration-line')
    }

    /**
     * 文本修饰线：线条的类型
     */
    set decorationLine(val) {
        if (!/^(none|(\s*underline|\s*overline|\s*line-through))+$/.test(val)) {
            val = ''
        } else if (this.getCss.call(this.parentElement, 'text-decoration-line') === val) {
            val = ''
        }
        this.decoration = `${val} ${this.decorationStyle} ${this.decorationColor} ${this.decorationThickness}`
    }

    /**
     * 文本修饰线：颜色
     */
    get decorationColor() {
        return this.getCss('text-decoration-color')
    }

    /**
     * 文本修饰线：颜色
     */
    set decorationColor(val) {
        if (!ColorRegexp.test(`${val}`)) {
            val = ''
        }
        this.decoration = `${this.decorationLine} ${this.decorationStyle} ${val} ${this.decorationThickness}`
    }

    /**
     * 文本修饰线：线条的形状
     */
    get decorationStyle() {
        return this.getCss('text-decoration-style')
    }

    /**
     * 文本修饰线：线条的形状
     */
    set decorationStyle(val) {
        if (!/^(solid|double|dotted|dashed|wavy)$/.test(val)) {
            val = ''
        }
        this.decoration = `${this.decorationLine} ${val} ${this.decorationColor} ${this.decorationThickness}`
    }

    get decorationThickness() {
        return this.getCss('text-decoration-thickness')
    }

    set decorationThickness(val) {
        val = `${val}`
        if (!LengthRegexp.test(val) && !/^(auto|from-font)$/.test(val)) {
            val = ''
        }
        this.decoration = `${this.decorationLine} ${this.decorationStyle} ${this.decorationColor} ${val}`
    }

    /**
     * text-align
     */
    get align() {
        return this.getCss('text-align')
    }

    /**
     * text-align
     */
    set align(val) {
        if (!/^(start|end|left|right|center|justify|match-parent|justify-all)$/.test(val)) {
            val = null
        }
        this.setCss('text-align', val)
    }

    /**
     * line-height
     */
    get height() {
        return this.getCss('line-height')
    }

    /**
     * line-height
     */
    set height(val) {
        if (!LengthRegexp.test(val)) {
            val = null
        }
        this.setCss('line-height', val)
    }

    /**
     * letter-spacing
     */
    get letter() {
        return this.getCss('letter-spacing')
    }

    /**
     * letter-spacing
     */
    set letter(val) {
        if (!LengthRegexp.test(val)) {
            val = null
        }
        this.setCss('letter-spacing', val)
    }

    /**
     * word-spacing
     */
    get word() {
        return this.getCss('word-spacing')
    }

    /**
     * word-spacing
     */
    set word(val) {
        if (!LengthRegexp.test(val)) {
            val = null
        }
        this.setCss('word-spacing', val)
    }

    /**
     * 字体颜色
     */
    get color() {
        return this.getCss('color')
    }

    /**
     * 字体颜色
     */
    set color(val) {
        if (!ColorRegexp.test(`${val}`)) {
            val = null
        }
        this.setCss('color', val)
    }
}
